import React, {Component} from 'react';
import {Input, Button, Form,Upload,Icon} from 'antd';
import './com_information_update.less';
import {reqCompanyInformation, reqUpdateCompanyInformation} from '../../api/index'

/*
* 公司信息路由*/

class UpdateComInformation extends Component {

    state = {
        companyInformation: [],//总的公司信息列表
        companyId: 0,
        licenseName:'营业执照',
        url:'http://39.100.133.204:8000/media/com_license/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20191022155038.png',
    }


//异步获取公司基本信息

    getCompanyInformation = async () => {

        //发异步ajax请求，获取数据
        const result = await reqCompanyInformation()
        const companyInformation = result.data[0]
        //更新状态
        this.setState({
            companyInformation: companyInformation,
            companyId: companyInformation.id,
            // url:"'"+companyInformation.license+"'"
        })
    }

    //发异步ajax请求
    componentDidMount() {

    }

    //为第一次render()准备数据
    componentWillMount() {
        this.getCompanyInformation()
    }


    submit = e => {
        e.preventDefault();
        //进行表单验证，如果通过了，才发送请求
        this.props.form.validateFields(async (err, values) => {
            if (!err) {
                //1、搜集数据
                const companyId = this.state.companyId
                const {name, describe, address, logo, license, contact, contact_phone} = values
                console.log(license)
                const result = await reqUpdateCompanyInformation(companyId, name, describe, address,contact, contact_phone,logo, license)

                //跳转到充值界面
                this.props.history.push('/com_information')
                //3、根据结果提示
            } else {
                console.log('发送ajax请求失败 ');
            }
        });
    }

    render() {
        //读取状态数据
        const {getFieldDecorator} = this.props.form;
        const {name, describe, address,contact, contact_phone,logo,license} = this.state.companyInformation
        const {licenseName,url}=this.state
        console.log(url)
        // const fileList = [
        //     {
        //         uid: '1',
        //         name: licenseName,
        //         status: 'done',
        //         url: url,
        //         thumbUrl: url,
        //     },
        // ];
        //
        // const props = {
        //     action: '/media/com_license/',
        //     listType: 'picture',
        //     defaultFileList: [...fileList],
        // }
        return (
            <div className="recruit">
                <div><h1>修改公司信息</h1></div>
                <Form layout="inline" onSubmit={this.submit} encType="multipart/form-data">
                    <div className="recruit-style">
                        <div>
                            <Form.Item label="公司名称">
                                {getFieldDecorator('name', {
                                    initialValue: name
                                })(<Input className="recruit-style-input"/>)}
                            </Form.Item>
                        </div>
                        <div><Form.Item label="公司介绍">{getFieldDecorator('describe', {
                            initialValue: describe
                        })(<Input className="recruit-style-input"/>)}</Form.Item>
                        </div>
                        <div><Form.Item label="公司地址">{getFieldDecorator('address', {
                            initialValue: address
                        })(<Input
                            className="recruit-style-input2"/>)}
                        </Form.Item></div>
                        <div><Form.Item label="联系人">{getFieldDecorator('contact', {
                            initialValue: contact
                        })(<Input
                            className="recruit-style-input1"/>)}
                        </Form.Item></div>
                        <div><Form.Item label="联系电话">{getFieldDecorator('contact_phone', {
                            initialValue: contact_phone
                        })(<Input
                            className="recruit-style-input2"/>)}
                        </Form.Item></div>
                        {/*<div><Form.Item label="营业执照">{getFieldDecorator('license', {*/}
                        {/*    initialValue: license*/}
                        {/*})(<Upload {...props} className="recruit-style-input2">*/}
                        {/*    <Button>*/}
                        {/*        <Icon type="upload" />营业执照上传*/}
                        {/*    </Button>*/}
                        {/*</Upload>)}*/}
                        {/*</Form.Item></div>*/}
                    </div>
                    <Form.Item>
                        <Button type="primary" htmlType="submit">
                            保存
                        </Button>
                    </Form.Item>
                </Form>
            </div>
        )
    }
}

const WrappedUpdateComInformation = Form.create()(UpdateComInformation);
export default WrappedUpdateComInformation;
